package com.example.wan1.view.wechat;

import com.example.wan1.data.BaseObserver;
import com.example.wan1.data.RetrofitUtil;
import com.example.wan1.data.RxSchedulers;
import com.example.wan1.model.ArticleBean;
import com.example.wan1.model.KnowledgeBean;
import com.example.wan1.model.common.CommonResList;

import java.util.List;

import javax.inject.Inject;

/***
 * 创建时间：2020/7/11 10:47
 * 创建人：10850
 * 功能描述：
 */
public class WechatPresenter
        implements WeChatContract.Presenter {

    @Inject
    WeChatContract.View mView;

    @Inject
    public WechatPresenter() {

    }

    @Override
    public void getWechatTitleList() {
        RetrofitUtil.getInstance().getWechatTitleList()
                .compose(RxSchedulers.observableIO2Main())
                .subscribe(new BaseObserver<List<KnowledgeBean>>() {
                    @Override
                    public void onSuccess(List<KnowledgeBean> result) {
                        mView.onGetTitle(result);
                    }

                    @Override
                    public void onFailure(Throwable e, String errorMsg) {
                        mView.onFailure(e.getMessage());
                    }
                });
    }

    @Override
    public void getWechatDataList(int id, int page) {
        RetrofitUtil.getInstance().getWechatDataList(id, page)
                .compose(RxSchedulers.observableIO2Main())
                .subscribe(new BaseObserver<CommonResList<ArticleBean>>() {

                    @Override
                    public void onSuccess(CommonResList<ArticleBean> result) {
                        mView.onSuccess(result);
                    }

                    @Override
                    public void onFailure(Throwable e, String errorMsg) {
                        mView.onFailure(e.getMessage());
                    }
                });
    }

    @Override
    public void getWechatSearchList(int id, int page, String k) {
        RetrofitUtil.getInstance().getWechatSearchData(id, page, k)
                .compose(RxSchedulers.observableIO2Main())
                .subscribe(new BaseObserver<CommonResList<ArticleBean>>() {

                    @Override
                    public void onSuccess(CommonResList<ArticleBean> result) {
                        mView.onSuccess(result);
                    }

                    @Override
                    public void onFailure(Throwable e, String errorMsg) {
                        mView.onFailure(e.getMessage());
                    }
                });
    }
}
